package com.eric.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eric.bean.User;
import com.eric.service.IUserService;
import com.sun.javafx.collections.MappingChange.Map;


@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService userService;

    @RequestMapping("/list")
    public String findList(HttpServletRequest request, Model model) {
       List<User> userList = this.userService.list();
       model.addAttribute("userList", userList);
        return "showUser";
    }
    
    @RequestMapping("/showUser")
    public String toIndex(HttpServletRequest request, Model model) {
        List<java.util.Map> userList = this.userService.getFullUser();
        System.out.print("-------------------------------长度"+userList.size());
        model.addAttribute("userList", userList);
        return "showUser";
    }
    
    @RequestMapping("/add")
    public String  add(HttpServletRequest request, Model model){
    	String userName = request.getParameter("userName");
    	String passWord = request.getParameter("passWord");
    	String ageStr = request.getParameter("age");
    	
    	int age = Integer.parseInt(ageStr);
    	
    	User user = new User();
    	
    	user.setUserName(userName);
    	user.setPassword(passWord);
    	user.setAge(age);
    	
    	this.userService.doAdd(user);
    	return "showUser";
    	
    }
}
